<!--<!DOCTYPE html>

<html>

	<head>
		<meta charset="utf-8">
		<title>车协官网后台管理</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">

		<link rel="stylesheet" href="/admin/plugins/layui/css/layui.css" media="all" />
		<link rel="stylesheet" href="/admin/css/global.css" media="all">
		<link rel="stylesheet" href="/admin/plugins/font-awesome/css/font-awesome.min.css">

	</head>

	<body>
		<div class="layui-layout layui-layout-admin">
			<div class="layui-header header header-demo">
				<div class="layui-main">
					<div class="admin-login-box">
						<a class="logo" style="left: 0;" href="http://beginner.zhengjinfan.cn/demo/beginner_admin/">
							<span style="font-size: 22px;">后台管理</span>
						</a>
						<div class="admin-side-toggle">
							<i class="fa fa-bars" aria-hidden="true"></i>
						</div>
					</div>
					<ul class="layui-nav admin-header-item">
						<li class="layui-nav-item">
							<span>欢迎您<%=host%>:</span>
						</li>
						<li class="layui-nav-item">
							<a href="/" target="_blank">浏览网站</a>
						</li>
						<li class="layui-nav-item" >
							<a href="/logout"><i class="fa fa-sign-out"></i> 注销</a>
						</li>

					</ul>

				</div>
			</div>
			<div class="layui-side layui-bg-black" id="admin-side">
				<div class="layui-side-scroll" id="admin-navbar-side" lay-filter="side"></div>
			</div>
			<div class="layui-body" style="bottom: 0;border-left: solid 2px #1AA094;" id="admin-body">
				<div class="layui-tab admin-nav-card layui-tab-brief" lay-filter="admin-tab">
					<ul class="layui-tab-title">
						<li class="layui-this">
							<i class="fa fa-dashboard" aria-hidden="true"></i>
							<cite>主页</cite>
						</li>
					</ul>-->
					<%include common/include_header.html%>
					<style type="text/css">
						/*.order-input{text-align: center;width: 100px;}*/
					</style>
					<div class="layui-tab-content" style="min-height: 150px; padding: 5px 0 0 0;">
						<div>
							<div style="margin: 15px;">
	<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
		<legend>添加删除轮播图</legend>
	</fieldset>
	<form enctype="multipart/form-data" onsubmit="return;">
    添加文件：<input type="file" id="file" name="upload" multiple="multiple" accept="image/png,image/gif,image/jpg,image/jpeg">
    排序:<input type="number" name="sort" id="sort" min="1" value="1" required="required" />
    <!--<input type="submit" value="Upload file" />-->
    <div style="color: red;">建议尺寸1920*520,仅支持png、gif、jpg格式图片，选择文件后请点击上传</div>
    <input type="button" style="display: none;" id="submit" value="上传" />
   
</form>
<!--<video src="/web/video/1541223155000.mp4" controls="controls">
您的浏览器不支持 video 标签。
</video>-->

	<table class="layui-table" style="width: 1200px;">
  <colgroup>
    <col width="150">
    <col width="200">
    <col>
  </colgroup>
  <thead>
    <tr>
      <th>序号</th>
      <th>图片</th>
      <th>排序(数字越小排越前面)</th>
      <th>操作</th>
    </tr> 
  </thead>
  <tbody>
  </tbody>
</table>
</div>
<style type="text/css">
	.btn{position: relative;width: 100px;height: 50px;}
  .zhe{position: absolute;top: 0;left: 0;width: 100px;height: 50px;}
  .img{width: 300px;height: 300px;}
  .delC{width: 100px;height: 40px;}
</style>
						</div>
					</div>
				
			<%include common/include_footer.html%>
			<!--<div class="layui-footer footer footer-demo" id="admin-footer">
				<div class="layui-main">
					<p>2018 &copy;
						<a href="/">惠升后台管理系统</a> LGPL license
					</p>
				</div>
			</div>
			<div class="site-tree-mobile layui-hide">
				<i class="layui-icon">&#xe602;</i>
			</div>-->

			
			<script type="text/javascript" src="/admin/plugins/layui/layui.js"></script>
			<!--<script type="text/javascript" src="/admin/datas/nav.js"></script>-->
			<script src="/admin/js/index1.js"></script>
			<script>
function delCarousel(id){
		layer.confirm("你确认删除这张轮播图吗",function(){
			$.post("/admin/del_carousel",{id:id},function(data){
				if(data.status=="success"){
					layer.alert("删除成功",function(){
						location.reload();
					})
				}else{
					layer.alert("删除失败",function(){
						location.reload();
					})
				}
	})
		})
	}
	layui.use(['layer','form', 'laydate','upload'], function() {
		var form = layui.form(),
				layer = layui.layer,
				laydate = layui.laydate,
				$= layui.jquery;

	$.post("/admin/get_carousel",{},function(data){
		console.log(data)
		var data=data.carousel;
		for(var i=0;i<data.length;i++){
			var id=data[i]._id;
		$(".layui-table tbody").append(' <tr><td>'+(i+1)+'</td><td><img src="'+""+"/"+data[i].url+'" class="img"/></td><td><input value="'+data[i].sort+'" class="order-input" data-id='+data[i]._id+' /></td><td><button class="del-btn" mid=\''+id+'\'  class="delC">删除</button></td></tr>')
		}
	})
	//删除轮播图
	$(".layui-table").on("click",".del-btn",function(){
		var id=$(this).attr("mid");
		layer.confirm("你确认删除这张轮播图吗",function(){
			$.post("/admin/del_carousel",{id:id},function(data){
				if(data.status=="success"){
					layer.alert("删除成功",function(){
						location.reload();
					})
				}else{
					layer.alert("删除失败",function(){
						location.reload();
					})
				}
	})
		})
	})
 $("#submit").on("click",function(){
		var form = new FormData($("form")[0]);  
		console.log(form)
		layer.alert('上传中，请勿进行任何操作');
		if(form){
    $.ajax({  
        url: "/upload",  
        type: "post",  
        data: form,  
        dataType: "multipart/form-data",  
        processData: false,  
        contentType: false,  
        async: false,  
        success: function (res) { 
          
          console.log(res)
          window.reload()
        },
        error:function(req){
         console.log(req.responseText)
//       window.reload()
       }
    })  
   }else{
   	layer.alert("请上传文件");
   }
    })
		//监听提交
		//点击添加分类
		$('#add').on('click', function() {
			var name=$("#name").val();
			var time=$("#time").val();
			var department=$("#department").val();
			//测试用户是否录入信息
			if(name==""||time==""||department==""){
				layer.alert('请填入相关信息', {icon: 2});
				return;
			}
			$.post("/admin/add_quit",{name:name,time:time,department:department},function(result){
				if(result.status==="success"){
					layer.alert('添加成功,请在离职公示列表查看。', {icon: 1});
				}else{
					layer.alert('添加失败', {icon: 2});
				}
			});
			//这句话的意思不会刷新当前页面。避免清空内容
			return false;
		});
		$("#sort").blur(function(){
		  if($(this).val()<1||isNaN(Number($(this).val()))){
		    $(this).val(1)
		  }
		})
		$("#file").change(function(){
      $("#submit").removeAttr("disabled")
      if($("#sort").val()||$("#sort").val()>0){
        $("#submit").show();
      }
      
    })
    $(".zhe").click(function(){
      console.log(!$("#submit").attr("disabled"))
      if(!$("#submit").attr("disabled")){
      var index = layer.load(1, {
        shade: [0.5,'#000'] //0.1透明度的白色背景
      });
      layer.alert('上传中，请勿进行任何操作,如果中途关闭或刷新上传视频会被中断');
    }
      $("#submit").trigger("click");
    })
    
    $("body").on("blur",".order-input",function(){
      if($(this).val()<1||isNaN(Number($(this).val()))){
        $(this).val(1)
      }
      $.post("/admin/edit_carouselSort",{_id:$(this).data("id"),sort:$(this).val()},function(result){
          if(result.status==="success"){
            return false;
          }else{
            layer.alert('修改失败', {icon: 2});
            return false;
          }
        });
    })
    
	});
	function imgPreview(fileDom) {
    //判断是否支持FileReader
    if(window.FileReader) {
        var reader = new FileReader();
    } else {
        alert("您的设备不支持图片预览功能，如需该功能请升级您的设备！");
    }
    //获取文件
    var file = fileDom.files[0];
    var imageType = /^image\//;
    //是否是图片
    if(!imageType.test(file.type)) {
        alert("请选择图片！");
        return;
    }
    //读取完成
    reader.onload = function(e) {
        //获取图片dom
        var img = document.getElementById("preview");
        //图片路径设置为读取的图片
        img.src = e.target.result;
    };
    reader.readAsDataURL(file);
}
	
			</script>
		</div>
	</body>

</html>